<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>工作时间管理</title>


    <link type="text/css" href="/TopJUI/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/TopJUI/topjui/themes/default/topjui.green.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/TopJUI/topjui/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="/TopJUI/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="/TopJUI/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="/TopJUI/topjui/js/locale/topjui.lang.zh_CN.js"></script>

    <script type="text/javascript" src="/pages/js/moment.min.js"></script>
    <script type="text/javascript" src="/pages/js/layer/layer.js"></script>
    <script type="text/javascript" src="/pages/js/util.js"></script>

    <script type="text/javascript" src="/pages/js/base-loading.js"></script>
    <script type="text/javascript" src="/pages/js/shuoheUtil.js"></script>

    <style type="text/css">
        html, body{ margin:0; height:100%; }
    </style>

</head>
<body class="easyui-layout">
  <script type="text/javascript">
  </script>
    <div data-options="region:'west',iconCls:'icon-reload',title:'',split:true" style="width:20%;">           
        <div id="dg_tb" style="height: 35px;text-align: center;">
            <a id='btnUpdate' href="javascript:void(0)" class="easyui-linkbutton" 
                data-options="iconCls:'fa fa-pencil',plain:true"
                style="width: 100%;background-color: #00CD66" 
                onclick="addYearWorkCalendar()"
            >添加年度工作日历</a>
        </div>   
        <table id="tt" style="height:100%;width: 100%;" title="" data-options="
                  idField:'id',
                  treeField:'text',
                  method:'get',
                  toolbar:'#dg_tb',
                ">
          <thead>
              <tr>
                  <th field="text" width="100%">年度</th>
                  <th field="id" width="0px" hidden="true">序列</th>
              </tr>
          </thead>
        </table>        
    </div>
    <div data-options="region:'center',iconCls:'icon-reload',title:'',split:true" style="width:100%;height: 100%">
        <table id="dg" class='easyui-datagrid' style="width:100%;height:100%" title="" data-options="
                  rownumbers:true,
                  singleSelect:true,
                  autoRowHeight:false,
                  pagination:false,
                  fitColumns:false,
                  striped:false,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:true,
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
              <tr href="#">
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th field="id" align="center" hidden ="true">id</th>
                    <th field="day_date" formatter='formatDateTimeYMD'>日期</th>
                    <th field="is_weekend" formatter="formatWeeked">是否周末</th>
                    <th field="is_holiday" formatter="formatHoliday">是否假日</th>
              </tr>
            </thead>
          </table>
          <div id="tb" style="height:35px">            
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-gamepad',plain:true" onclick="setHoliday(true)" style="margin-left: 30px">设为节假日</a>  
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-git',plain:true" onclick="setHoliday(false)">设为工作日</a>              
<!--             <form id="queryForm" class="search-box">
                  <input class="easyui-textbox" id='equipment_id' data-options="prompt:'公司名称'">
                  <input class="easyui-textbox" id='equipment_name' data-options="prompt:'公司地址'">
                  <a id='btnQuery' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-search" onclick="functionQuery()" style="margin-left: 0px">搜索</a>          
                  <a id='btnClear' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-refresh" onclick="functionClear()" style="margin-left: 0px">清除</a>                     
              </form>   -->          
          </div>
       </div>
    </div>


<script type="text/javascript">

    function formatWeeked(val, row) {
        if (row.is_weekend == true) {
            return '<span>是</span>';
        } else
            return '<span>否</span>';
    }

    function formatHoliday(val, row) {
        if (row.is_holiday == true) {
            return '<span>是</span>';
        } else
            return '<span>否</span>';
    }

    $(function() {



        $('#tt').treegrid({
            url: '/pm2/workcalendar/getList.do',
            onClickRow: function(rowIndex) {
                var rr_row = $('#tt').treegrid('getSelected');
                $('#dg').datagrid({
                    url: '/develop/url/getUrl.do',
                    queryParams: {
                        'name': 'getDaysByPid',
                        'pid': rr_row.id
                    },
                    method: 'get',
                    rowStyler: function(index, row) {
                        if (row.is_holiday == true) {
                            return 'background-color:DeepSkyBlue;';
                        }
                        if (row.is_weekend == true) {
                            return 'background-color:HotPink;';
                        }

                    },
                })
            },
            onLoadSuccess: function(data) {}
        })
    });
    function setHoliday(result)
    {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        shuoheUtil.layerTopMaskOn();

         $.ajax({
            url:'/pm2/workcalendar/setHoliday.do',
            type: "POST",
            dataType: 'json',
            data: {
                'is_holiday': result,
                'id':row.id
            },
            error: function() //失败
            {
                shuoheUtil.layerTopMaskOff();
            },
            success: function(data) //成功
            {
                shuoheUtil.layerTopMaskOff();
                if (data.result == true) {
                    parent.updateSuccess();
                } else
                    shuoheUtil.layerMsgCustom(data.describe);
            }
        });
    }

</script>




</body>
</html>
<script type="text/javascript">
    function add() {
        layer.open({
            type: 2,
            title: '新增设备',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮s
            area: ['800px', '400px'],
            content: 'form/addProject.jsp'
        })
    }

    function view() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        layer.open({
            type: 2,
            title: '查看设备',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '400px'],
            content: 'form/viewProject.jsp?id=' + row.id + '&id=' + row.id
        })
    }

    function edit() {

        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        layer.open({
            type: 2,
            title: '修改设备',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '400px'],
            content: 'form/editProject.jsp?id=' + row.id + '&id=' + row.id
        })
    }

    function dele() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }
        //删除操作属于危险操作，给出提示
        $.messager.confirm('友情提示', '您确定要删除这条数据吗?', function(r) {
            if (r) {
                shuoheUtil.layerTopMaskOn();
                $.ajax({
                    url: "/mro/equipment/equipment/delete.do",
                    type: "POST",
                    dataType: 'json',
                    data: {
                        'id': row.id
                    },
                    error: function() //失败
                    {
                        shuoheUtil.layerTopMaskOff();
                    },
                    success: function(data) //成功
                    {
                        updateSuccess();
                        shuoheUtil.layerTopMaskOff();
                        if (data.result) {
                            shuoheUtil.layerMsgOK(data.describe);
                        } else {
                            shuoheUtil.layerMsgError(data.describe);
                        }
                    }
                });
            }
        });
    }

    function updateSuccess() {
        $('#dg').datagrid('reload');
        $('#tt').treegrid('reload');
    }

    function functionQuery() {
        loadDg();
    }

    function functionClear() {
        $('#equipment_id').textbox('clear');
        $('#equipment_name').textbox('clear');
        $('#use_department').textbox('clear');
        $('#actual_name').textbox('clear');
        loadDg();
    }

    function addYearWorkCalendar() {
        layer.open({
            type: 2,
            title: '新增年度工作日',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['500px', '200px'],
            content: 'addWorkCalendar.jsp'
        })
    }
</script>

